import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'controller/welcom_controller.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2020/7/21.
///
/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2020/9/25.
///
/// gongzhonghao biglead
/// gongzhonghao biglead
/// github https://github.com/zhaolongs
/// bili https://space.bilibili.com/513480210
/// zhihu https://www.zhihu.com/people/zhao-long-90-89
/// csdn https://blog.csdn.net/zl18603543572
/// 西瓜视频 https://www.ixigua.com/home/3662978423///
///lib/src/welcome_page.dart
///代码清单12-5 广告倒计时欢迎页面
class WelcomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //注入控制器
    Get.put(WelcomController());

    return Scaffold(
      body: SizedBox(
        width: double.infinity,
        height: double.infinity,
        //层叠布局
        child: Stack(
          children: [
            //背景图片
            Positioned.fill(
              child: Image.asset(
                "assets/images/welcome_bg.jpeg",
                fit: BoxFit.fill,
              ),
            ),
            //倒计时使用的进度圆圈
            buildTimerProgress(),
          ],
        ),
      ),
    );
  }

  //lib/src/welcome_page.dart
  //可点击的 倒计时进度圆圈
  Positioned buildTimerProgress() {
    return Positioned(
      //右上角对齐
      right: 20, top: 60,
      //点击事件回调
      child: InkWell(
        onTap: () {
          //调用控制器中的方法
          Get.find<WelcomController>().goHome();
        },
        child: GetBuilder(
          id: "progress",
          builder: (WelcomController controller) {
            //初始的时间
            double progress = controller.progress;
            //倒计时时间
            double totalProgress = controller.totalProgress;
            return Stack(
              alignment: Alignment.center,
              children: [
                CircularProgressIndicator(
                  value: progress / totalProgress,
                ),
                Text(
                  "${progress ~/ 1000}",
                  style: const TextStyle(color: Colors.white),
                )
              ],
            );
          },
        ),
      ),
    );
  }
}
